<!--
  ~  Copyright 2024 konsoletyper.
  ~
  ~  Licensed under the Apache License, Version 2.0 (the "License");
  ~  you may not use this file except in compliance with the License.
  ~  You may obtain a copy of the License at
  ~
  ~       http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~  Unless required by applicable law or agreed to in writing, software
  ~  distributed under the License is distributed on an "AS IS" BASIS,
  ~  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~  See the License for the specific language governing permissions and
  ~  limitations under the License.
  -->

<!DOCTYPE html>
<html>
  <head>
    <title>TeaVM WebAssembly disassembler</title>
    <style>
      .disassembly em {
          color: grey;
      }
    </style>
    <script src="wasm-gc-runtime.js"></script>
  </head>
  <body>
    <p>Please, note that this is not full disassembler, it only supports subset of WebAssembly
      used by TeaVM.</p>
    <div>
      <input type="file" id="file-input">
    </div>
    <pre class="disassembly" id="disassembly-output">
    </pre>
    <script>
      async function load() {
          let fileInput = document.getElementById("file-input");
          fileInput.disabled = true;
          let disassemblyOutput = document.getElementById("disassembly-output");
          let module = await TeaVM.wasmGC.load("disassembler.wasm");
          let disassemble = module.exports.disassemble;
          fileInput.disabled = false;
          fileInput.onchange = () => {
              fileInput.disabled = true;
              (async () => {
                  let file = fileInput.files[0];
                  let buffer = await file.arrayBuffer();
                  fileInput.disabled = false;
                  let array = new Int8Array(buffer);
                  disassemblyOutput.innerHTML = disassemble(array);
              })();
          };
      }
      load()
    </script>
  </body>
</html>